//
//  YTKKeyValueStore.h
//  Ape
//
//  Created by TangQiao on 12-11-6.
//  Copyright (c) 2012年 TangQiao. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface WDKeyValueItem : NSObject

@property (strong, nonatomic) NSString *itemId;
@property (strong, nonatomic) id itemObject;
@property (strong, nonatomic) NSDate *createdTime;

@end


@interface WDKeyValueStore : NSObject

+ (instancetype)shareInstance;
//根据表名实例化数据库
- (id)initDBWithName:(NSString *)dbName;
//根据db路径实例化数据库
- (id)initWithDBWithPath:(NSString *)dbPath;
//创建数据库表
- (void)createTableWithName:(NSString *)tableName;
//判断数据库表是否存在
- (BOOL)isTableExists:(NSString *)tableName;
//清除数据库表
- (void)clearTable:(NSString *)tableName;
//关闭数据库操作
- (void)close;

//************************ Put&Get methods *****************************************

#pragma mark - 增改
/*
 新增、更新数据库
 objectId   唯一标识
 tableName  数据库表名
 **/
- (void)putObject:(id)object withId:(NSString *)objectId intoTable:(NSString *)tableName;

- (void)putString:(NSString *)string withId:(NSString *)stringId intoTable:(NSString *)tableName;

- (void)putNumber:(NSNumber *)number withId:(NSString *)numberId intoTable:(NSString *)tableName;

#pragma mark - 查询
/*
 根据id获取value
 objectId   唯一标识
 tableName  数据库表名
 **/
- (id)getObjectById:(NSString *)objectId fromTable:(NSString *)tableName;

- (NSString *)getStringById:(NSString *)stringId fromTable:(NSString *)tableName;

- (NSNumber *)getNumberById:(NSString *)numberId fromTable:(NSString *)tableName;

- (WDKeyValueItem *)getWDKeyValueItemById:(NSString *)objectId fromTable:(NSString *)tableName;

/**
 获取数据库中所有的Items

 @param tableName 数据库表名
 @return itemObject集合
 */
- (NSArray *)getAllItemsFromTable:(NSString *)tableName;

/**
 根据itemID获取所有相同的items

 @param ItemID 唯一标识
 @param tableName 数据库表名
 @return itemObject集合
 */
- (NSArray *)getItemsWithItemID:(NSString *)ItemID fromTable:(NSString *)tableName;

/**
 通过关键字精确获取values

 @param key itemObject的key
 @param value itemObject的value
 @param tableName 数据库表名
 @return itemObject集合
 */
- (NSArray *)getItemsByKeywordWithKey:(NSString *)key value:(id)value fromTable:(NSString *)tableName;

/**
 通过关键字模糊搜索values

 @param key itemObject的key
 @param value itemObject的value
 @param tableName 数据库表名
 @return itemObject的集合
 */
- (NSArray *)getItemsByFuzzyKeywordWithKey:(NSString *)key value:(id)value fromTable:(NSString *)tableName;
/*
 获取数据库表中数据的条数
 **/
- (NSUInteger)getCountFromTable:(NSString *)tableName;

#pragma mark - 删除

/**
 根据itemID来从数据表中删除

 @param objectId 唯一标识
 @param tableName 数据库表名
 */
- (void)deleteObjectById:(NSString *)objectId fromTable:(NSString *)tableName;
/**
 根据itemIDs来从数据表中删除多个item
 
 @param objectIdArray 唯一标识集合
 @param tableName 数据库表名
 */
- (void)deleteObjectsByIdArray:(NSArray *)objectIdArray fromTable:(NSString *)tableName;


- (void)deleteObjectsByIdPrefix:(NSString *)objectIdPrefix fromTable:(NSString *)tableName;

@end
